import { createRouter, createWebHashHistory, RouterOptions, Router, RouteRecordRaw, RouterHistory } from 'vue-router'
import { routerData } from './router-data.ts'
//由于router的API默认使用了类型进行初始化，内部包含类型定义，所以本文内部代码中的所有数据类型是可以省略的
// const routeData =
let routes = []
let routesFn = data => data.map(item => {
  // 有children时
  if (item.hasOwnProperty('children') && item.children.length) {
    routesFn(item.children)
  } else {
    routes.push(item)
  }
})
console.log('routeData-------->', routerData)
routesFn(routerData)

console.log('routes------->',routes)
//RouterRecordRaw是路由组件对象
// let routes = [
//   { path: '/login', name: 'Login', component: () => import('@/views/login/index.vue') },
//   // 首页
//   { path: '/', redirect: '/home' },
//   { path: '/home', name: 'Home', component: () => import('@/views/home/index.vue') },
//   // 换肤
//   { path: '/theme', name: 'Theme', component: () => import('@/views/theme/index.vue') },
//   // 计算
//   { path: '/calculate/server', name: 'Calculate', component: () => import('@/views/calculate/server/index.vue') },
//   { path: '/calculate/server/server-detail', name: 'Server', component: () => import('@/components/calculate/server/server-detail/index.vue') },
//   // 404 page must be placed at the end !!!
//   { path: '/404', component: () => import('@/views/404/index.vue') },
//   { path: '/:catchAll(.*)', redirect: '/404', hidden: true },
// ]

// RouterOptions是路由选项类型
const route = {
  history: createWebHashHistory(),
  routes,
}

// Router是路由对象类型
const router: Router = createRouter(route)

export default router
